/**
 * CopyRight © 2012 USTC SINOVATE SOFTWARE CO.LTD All Rights Reserved.
 */

package com.cmcc.zysoft.infocollection.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import org.springframework.util.StringUtils;
import com.cmcc.zysoft.infocollection.model.Tag;
import com.starit.common.dao.hibernate.HibernateBaseDaoImpl;

/**
 * @author 袁凤建
 * <br />邮箱: yuan.fengjian@ustcinfo.com
 * <br />描述: TagPcDao.java
 * <br />版本: 1.0.0
 * <br />日期: 2013-9-28 下午5:03:20
 * <br />CopyRight © 2012 USTC SINOVATE SOFTWARE CO.LTD All Rights Reserved.
 */

@Repository
public class TagPcDao extends HibernateBaseDaoImpl<Tag, Long> {

	@Autowired
	private JdbcTemplate jdbcTemplate;
	
	/**
	 * 根据关键字查询标签信息(无分页).
	 * @param keyword 关键字
	 * @return map
	 */
	public Map<String, Object> getTags(String keyword) {
		Map<String, Object> map = new HashMap<String, Object>();
		String rowSql = 
				" SELECT tag.tag_id AS tagId, tag.tag_name AS tagName, tag.mark1 AS mark1, tag.mark2 AS mark2, tag.mark3 AS mark3, " +
				" tag.mark4 AS mark4 FROM tb_b_tag tag ";
		String countSql = "SELECT COUNT(*) FROM tb_b_tag tag ";
		if(StringUtils.hasText(keyword)) {
			rowSql += " WHERE tag.tag_name LIKE '%" + keyword + "%'";
			countSql += " WHERE tag.tag_name LIKE '%" + keyword + "%'";
		}
		List<Map<String, Object>> list = this.jdbcTemplate.queryForList(rowSql);
		int total = this.jdbcTemplate.queryForInt(countSql);
		map.put("rows", list);
		map.put("total", total);
		return map;
	}
}